home *** CD-ROM | disk | FTP | other *** search
- /*************************************************************************************
- #
- # TGraphicCollection.cp
- #
- #
- # The TGraphicCollection class is a group of related TGraphic objects. Essentially,
- # the API for this class mimics the TGraphic class very closely, except that all of
- # the routines in TGraphicCollection pass in an index to which TGraphic object is being
- # referred to.
- #
- # Because this class relies so heavily on TGraphic, we share all of TGraphic's
- # limitations. In fact, any of the routines used to prepare drawing in TGraphic are
- # used without modification, since they apply to ALL TGraphic objects, regardless of
- # if they are in a collection or not.
- #
- # Note that this class isn't currently intended to be subclassed, so all of the methods
- # are non-virtual. This might change if at some point we determine we need to create
- # a subclass.#
- #
- # Author: Timothy Carroll
- # Apple Developer Technical Support
- # timc@apple.com
- #
- # Modification History:
- #
- # 6/1/96 TMC Initial Release
- #
- # Copyright © 1996 Apple Computer, Inc., All Rights Reserved
- #
- #
- # You may incorporate this sample code into your applications without
- # restriction, though the sample code has been provided "AS IS" and the
- # responsibility for its operation is 100% yours. However, what you are
- # not permitted to do is to redistribute the source as "DSC Sample Code"
- # after having made changes. If you're going to re-distribute the source,
- # we require that you make it clear in the source that the code was
- # descended from Apple Sample Code, but that you've made changes.
- #
- *************************************************************************************/
-
-
- #ifndef _TGRAPHICCOLLECTION_
- #define _TGRAPHICCOLLECTION_
-
- #pragma once
-
- #include "TGraphic.h"
-
- #if PRAGMA_ALIGN_SUPPORTED
- #pragma options align=power
- #endif
-
- // To provide an smaller, simpler interface, we'll define a couple of macros here. Their use is optional.
-
- #define NewGraphicCollection(resID) TGraphicCollection::NewCollection((resID))
- #define DisposeGraphicCollection(collection) (collection)->DisposeReference()
-
-
-
-
- class TGraphicCollection
- {
- public:
- /****************************************************************************************************
- Static Creator and Reference Counting
-
- These are the routines that handle the actual creation of the objects, along with reference
- counting and so on. You shouldn't need to call the reference counting routines yourself --
- instead, call the macros to create and destroy collections and they'll do the right thing.
-
- Note that DisposeReference is the routine actually responsible for destroying a collection
- when we're through.
-
- A TGraphicCollection is currently defined by a resource of type 'SptA' or sprite array.
- ****************************************************************************************************/
- static TGraphicCollection *NewCollection (SInt16 resID);
-
- void AddReference (void);
- void DisposeReference (void);
-
-
-
- /****************************************************************************************************
- Locking and Unlocking
-
- You are never required to lock a collection -- the routines run fine either way. We provide these
- functions because the main use of this class is for drawing sprites. In a game, most of the
- graphics will be allocated ahead of time and stick around until the game ends. By locking them
- down high, we ensure they won't need to be moved to make room for other handles that might need
- to be allocated.
- ****************************************************************************************************/
- OSErr LockCollection (void);
- OSErr UnlockCollection (void);
-
-
- /****************************************************************************************************
- Creating and destroying the collection
-
- The actual work to create and destroy the collection is done in the following two routines.
- CreateCollection loads the resource, gets the data and creates any TGraphic objects necessary
- for the collection. DestroyCollection simply reverses the process.
- ****************************************************************************************************/
- OSErr CreateCollection (void);
- OSErr DestroyCollection (void);
-
-
- /****************************************************************************************************
- Accessor Functions
-
- We define a few accessor functions to allow clients to get some information. At this point, we
- are advertising the TGraphics as something that can be obtained. We do not immediatly force
- a link to the TGraphic object when we send it to you. If you want a persistant link to the
- TGraphic object, you must create a link to it and properly dispose of it. Otherwise, make sure
- you don't destroy the TGraphicCollection until you are done with the TGraphic.
- ****************************************************************************************************/
-
- // We'll inline the first function for speed.
- SInt16 GetResID(void) {return fResID;}
- Rect GetBounds (UInt32 index);
- TGraphic *GetTGraphic (UInt32 index); // returns a naked TGraphic. Use sparingly.
-
-
- /****************************************************************************************************
- Utility Functions
-
- The main routines that TGraphic is known for. I won't explain them in detail here, check out
- the TGraphic class for details.
- ****************************************************************************************************/
- void CopyImage (UInt32 index, SInt32 top, SInt32 left, Boolean useBackground);
- Boolean HitTest (UInt32 index, SInt32 v, SInt32 h);
-
-
- protected:
-
-
- /****************************************************************************************************
- Constructor/Destructor
-
- The contructor and destructor shouldn't be called except internally by the class, so they
- have been made protected. The class does reference counting, and only calls the destructors when all clients
- are through with a class. If you call it yourself, Bad Things Happen.
- ****************************************************************************************************/
- TGraphicCollection (SInt16 resID);
- ~TGraphicCollection (void);
-
-
- /****************************************************************************************************
- Data Structures
-
- The actual data used to hold the TGraphicCollection. We make sure that the data is aligned
- properly for both PowerPC and 68K struct alignment.
- ****************************************************************************************************/
-
- Handle fGraphics; // 4 bytes
- SInt16 fResID; // 2 bytes
- UInt16 fReferenceCount; // 2 bytes, # of owners of this collection;
- UInt32 fNumberOfGraphics; // 4 bytes
- };
-
- #if PRAGMA_ALIGN_SUPPORTED
- #pragma options align=reset
- #endif
-
- #endif /* _TGRAPHICCOLLECTION_ */